import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop011_添加商品"

# 实例化浏览器对象 打开指定网站
driver = openBrowser(urlAdmin)
# 后台登录
DBshopLoginAdmin(driver)
# 点击添加商品
driver.find_element_by_xpath("(//a[@class = 'btn btn-primary'])[6]").click()

# 得出订单数量
s = driver.find_element_by_xpath("//body").text
l = "商品数\："
r = "\)"
num1 = reGetString(s,l,r)

time.sleep(1)
# 点击添加商品
driver.find_element_by_xpath("(//a[@class = 'btn btn-small btn-primary'])[1]").click()
# 输入添加商品信息
driver.find_element_by_id("goods_name").send_keys("苹果xs")
driver.find_element_by_id("goods_shop_price").send_keys("7999")
# 选项商品类型
driver.find_element_by_xpath("//select[@id = 'goods_type']/option[3]").click()
driver.find_element_by_xpath("(//button[@class = 'btn btn-small btn-primary'])[1]").click()

# 得出添加后的商品数量
s = driver.find_element_by_xpath("//body").text
num2 = reGetString(s,l,r)

# 判断
if int(num2)==int(num1)+1:
    writeLog("%s 测试通过" % (testCase))
else:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(driver)
driver.quit()

